package cn.itcast.demo.interceptors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
public class MarketIntercptor implements HandlerInterceptor {

    //获取一个日志的 输出对象
    Logger logger = LoggerFactory.getLogger(MarketIntercptor.class);


    //前置, 返回false表示拦截，返回true表示放行
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("客户来超市购物了，发生了箱包存储pre");
        return true;
    }

    //后置
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        logger.info("客户在超市完成购物了，发生了箱包取出post");
    }


    //完成
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        logger.info("客户走了，如果他忘了取包，我们要把他存的包丢掉");
    }
}
